package eteam.aps.systemservice.dal;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import eteam.aps.systeminterface.model.entity.DictionaryEntity;
import eteam.aps.systeminterface.model.entity.DictypeEntity;
import eteam.aps.systeminterface.model.enums.StateEnum;
import eteam.aps.systemservice.dal.mapper.IDicType;
import eteam.aps.systemservice.dal.mapper.IDicValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 字典数据操作类
 */
@Service
public class DicDal {
    @Autowired
    private IDicType dicType;
    @Autowired
    private IDicValue dicValue;

    /**
     * 获取字典分类列表
     *
     * @return
     */
    public List<DictypeEntity> getDicTypeList() {
        return dicType.selectList(new QueryWrapper<DictypeEntity>().orderByAsc("Sort"));
    }

    /**
     * 获取字典分类列表
     *
     * @return
     */
    public List<DictypeEntity> getDicTypeList(Wrapper<DictypeEntity> queryWrapper) {
        return dicType.selectList(queryWrapper);
    }

    /**
     * 获取字典值列表
     *
     * @return
     */
    public List<DictionaryEntity> getDicValueList() {
        return dicValue.selectList(new QueryWrapper<DictionaryEntity>().ne("State", StateEnum.Delete.getValue()).orderByAsc("Sort"));
    }

    /**
     * 添加字典值
     *
     * @param entity
     * @return
     */
    public Integer insertDicValue(DictionaryEntity entity) {
        return dicValue.insert(entity);
    }

    /**
     * 更新字典值
     *
     * @param entity
     * @return
     */
    public Integer updateDicValue(DictionaryEntity entity) {
        return dicValue.updateById(entity);
    }

    /**
     * 删除字典值
     *
     * @param dvId
     * @return
     */
    public Integer deleteDicValueById(Long dvId) {
        return dicValue.deleteById(dvId);
    }

    /**
     * 获取字典值列表
     *
     * @param typeCode
     * @return
     */
    public List<DictionaryEntity> getDicByType(String typeCode) {
        return dicValue.selectList(new QueryWrapper<DictionaryEntity>()
                .eq("FClass", typeCode)
                .eq("State", StateEnum.Enable.getValue())
                .orderByAsc("Sort"));
    }

    /**
     * 获取字典值列表
     *
     * @param typeCodes
     * @return
     */
    public List<DictionaryEntity> getDicByType(List<String> typeCodes) {
        return dicValue.selectList(new QueryWrapper<DictionaryEntity>()
                .in("FClass", typeCodes)
                .eq("State", StateEnum.Enable.getValue())
                .orderByAsc("Sort"));
    }
}
